﻿using System;
using System.Collections.Generic;
using System.Text;
using org.EDS;
using System.Threading;

namespace ConsoleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Server Start on " + Thread.CurrentThread.ManagedThreadId);
            Server serv = new Server(8080, 64, 4096);
            serv.OnGetConnected += new ConnectHandler(serv_OnGetConnected);
            serv.OnGetBytes += new ReadHandler(serv_OnGetBytes);
            serv.OnReadDone += new ReadFinishHandler(serv_OnReadDone);
            serv.Start();
            Console.Read();
            
        }

        static void serv_OnReadDone(Server Sender, ReadState EventArgs)
        {
            string ReadTxt = Encoding.UTF8.GetString(EventArgs.Stream.ToArray());
            Console.WriteLine("3>Reading finished on Thread ID " + Thread.CurrentThread.ManagedThreadId);
            Console.Write("3>\r\n");
            Console.Write(ReadTxt);
            //EventArgs.WorkHandler.Close();
        }

        static void serv_OnGetBytes(Server Sender, ReadState EventArgs)
        {
            Console.WriteLine("2>Get bytes " + EventArgs.Stream.Length);
            Console.WriteLine("2>Reading Thread ID " + Thread.CurrentThread.ManagedThreadId);
        }

        static void serv_OnGetConnected(Server Sender, ConnectedState EventArgs)
        {
            Console.WriteLine("1>"+EventArgs.RemoteIP + " use port " + EventArgs.RemotePort + " Connected to me");
            Console.WriteLine("1>Connected Thread ID " + Thread.CurrentThread.ManagedThreadId);
        }
    }
}
